//
//  JZHSelectViewController.m
//  极致荟
//
//  Created by hetao on 14-5-9.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHSelectViewController.h"

@interface JZHSelectViewController ()

@end

@implementation JZHSelectViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
+ (JZHSelectViewController *)focusType:(JZHFocusType *)type
{
    JZHSelectViewController *jzh=[[JZHSelectViewController alloc]init];
    jzh.focus=type;
    return jzh;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    [titleLabel setTextColor:[UIColor blackColor]];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    titleLabel.text = [self.focus tyepChinaes:self.focus.focusType];
    self.navigationItem.titleView= titleLabel;
    //设置左侧按钮
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;

    [self httpLoadType];
}

- (void)leftDrawerButtonPress:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

///加载该类型下的二级列表
- (void)httpLoadType
{
    if(self.focus.ftdic)
    {
        return;
    }
    //[MMProgressHUD showWithStatus:@"数据加载中..."];
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[self.focus tyepString:self.focus.focusType],@"attentionType", nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"attention/attentionCategory") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        
        if(rerurncode==0)
        {
            [MMProgressHUD dismiss];
            NSLog(@"%@",data);
            self.focus.ftdic=[data objectForKey:@"data"];
            [self.table reloadData];
        }else
        {
            [MMProgressHUD  showInformationWithTips:@"加载失败"];
        }
    }];
}
#pragma mark ---tableview代理---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.focus.ftdic.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str=@"adf";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    [cell.textLabel setFont:[UIFont systemFontOfSize:14]];
    cell.textLabel.text=[self.focus.ftdic[indexPath.row] objectForKey:@"name"];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    self.focus.selectft=self.focus.ftdic[indexPath.row];
    [self.navigationController popViewControllerAnimated:YES];
    
}

@end
